import wepy from 'wepy'
export default class extends wepy.mixin {
	data = {
		active: 0,
		// 分页页数
		pageIndex: '1',
		// 分页大小
		pageSize: '10',
		// 分类数据
		getGoodsListInfo: [],
		jifen: '',
		isLoading: false,
		isOver: false,
		urls: wepy.$instance.globalData.baseURl,
		option0: [{
			text: '分类',
			value: ''
		}],
		option1: [{
			text: '积分分段',
			value: ''
		}],
		option2: [{
				text: '升降序',
				value: ''
			},
			{
				text: '积分升序',
				value: '1'
			},
			{
				text: '积分降序',
				value: '2'
			}
			// {
			// 	text: '价格升序',
			// 	value: '3'
			// },
			// {
			// 	text: '价格降序',
			// 	value: '4'
			// }
		],
		value0: '',
		value1: '',
		value2: '',
		banwei: [],
		jftt: '/2020-09-28/202009282329461601306986670_c9j1s.png',
		jfbg: '/2020-09-28/202009282340211601307621388_g3h1k.png',
		wh: 0,
		huadong:false
	}
	onLoad() {
		this.pageIndex = '1';
		this.getGoodsListInfo = [];
		this.getGoodsList()
	}
	onShow() {
		if (wepy.getStorageSync('userId')) {
			this.getCatesList()
			this.getJfSetList()
			this.jifenlist()
			this.advertising()
			this.getPhoneHeight()
		} else {
			wx.navigateTo({
				url: '../../pages/Authorization/authorization',
			})
		}
	}
	methods = {
		// 点击商品跳转
		goGoodsDatils(id) {
			console.log('商品详情', id)
			wepy.navigateTo({
				url: '../../pages/goodsDatils/gooddatils?id=' + id,
			})
		},
		leibie(e) {
			this.pageIndex = '1';
			this.value0 = e.detail;
			this.getGoodsListInfo = [];
			this.getGoodsList()
		},
		shaix1(e) {
			this.pageIndex = '1';
			this.value1 = e.detail;
			this.getGoodsListInfo = [];
			this.getGoodsList()
		},
		shaix2(e) {
			this.pageIndex = '1';
			this.value2 = e.detail;
			this.getGoodsListInfo = [];
			this.getGoodsList()
		},
		wuyechongzhi() {
			wepy.navigateTo({
				url: '../../pages/payHouseMoney/payhousemoney'
			})
		},
		loadMore(e) {
			//判断数据是否正在请求中
			if (this.isLoading) {
				return
			}
			let num = parseInt(this.pageIndex)
			num++
			this.pageIndex = num.toString()
			this.getGoodsList()
		},
		scrolls(e) {
			if(e.detail.scrollTop>190){
				this.huadong=true;
			}else{
				this.huadong=false;
			}
		},
	}
	// 获取屏幕的可用高度
	async getPhoneHeight() {
		const res = await wepy.getSystemInfo()
		if (res.errMsg === 'getSystemInfo:ok') {
			this.wh = res.windowHeight;
			this.$apply()
		}
	}
	//广告版位
	async advertising() {
		const res = await wepy.post('baseRest/getAdCmsList', {
			// cateType: '1',
			parentId: "4movM",
		})
		if (res.statusCode != 200) {
			return wepy.noToast('获取数据失败')
		}
		console.log(res, 'lllllllllll')
		this.banwei = res.data.data
		this.$apply()
	}
	// 获取积分
	async jifenlist() {
		const res = await wepy.post('baseRest/getMemberRCoinAndJf', {
			memberId: wepy.getStorageSync('userId'),
		})
		console.log(res, "积分")
		if (res.statusCode != 200) {
			return wepy.noToast('获取数据失败')
		}
		this.jifen = res.data.data
		this.$apply()
	}
	// 获取分类数据
	async getCatesList() {
		const res = await wepy.post('baseRest/getChildCategoryList', {
			categoryId: '2',
		})
		console.log(res)
		if (res.statusCode != 200) {
			return wepy.noToast('获取数据失败')
		}
		this.option0 = [{
			text: '分类',
			value: ''
		}];
		for (var i = 0; i < res.data.data.length; i++) {
			this.option0.push({
				text: res.data.data[i].categoryName,
				value: res.data.data[i].id
			})
		}
		this.$apply()
	}
	// 获取积分段
	async getJfSetList() {
		const res = await wepy.post('baseRest/getJfSetList', {

		})
		console.log(res)
		if (res.statusCode != 200) {
			return wepy.noToast('获取数据失败')
		}
		this.option1 = [{
			text: '积分分段',
			value: ''
		}];
		for (var i = 0; i < res.data.data.length; i++) {
			this.option1.push({
				text: res.data.data[i].start + "-" + res.data.data[i].stop,
				value: res.data.data[i].id
			})
		}
		this.$apply()
	}
	async getGoodsList() {
		// 发起请求，先将值重置为true
		this.isLoading = true
		const res = await wepy.post('baseRest/getGoodsList', {
			categoryId: this.value0,
			pageIndex: this.pageIndex,
			pageSize: this.pageSize,
			isPoint: '1',
			searchType: this.value2,
			jfId: this.value1
		})
		console.log(res)

		if (res.statusCode != 200) {
			return wepy.noToast('获取数据失败')
		}

		this.getGoodsListInfo = [...this.getGoodsListInfo, ...res.data.data]
		// 赋值完，再重置为false
		this.isLoading = false
		this.$apply()
	}
}
